package com.me.springcloud.feign;

import java.util.List;
import java.util.Map;

import com.me.springcloud.feign.FeignTest.Contributor;

import feign.Feign;
import feign.Param;
import feign.Request.Options;
import feign.RequestLine;
import feign.Retryer;

//@HeaderMap 注解设置的请求头优先于其他方式设置的
//@Headers("Content-Type: application/json") 单独给put方法设置Content-Type请求头
//V find(@QueryMap Map<String, Object> queryMap);
public class FeignTest {

	static class Contributor {
		String login;
		int contributions;
	}

	public static void main(String... args) {
//		GitHub github = Feign.builder().logger(new Slf4jLogger()).decoder(new GsonDecoder()).target(GitHub.class, "https://api.github.com");
//
//		// Fetch and print a list of the contributors to this library.
//		List<Contributor> contributors = github.contributors("OpenFeign", "feign");
//		for (Contributor contributor : contributors) {
//			System.out.println(contributor.login + " (" + contributor.contributions + ")");
//		}

		GitHub jsonObject = Feign.builder().errorDecoder(new MyErrCoder()).decoder(new FastJsonDecoder()).options(new Options(3000, 15000))
				.retryer(Retryer.NEVER_RETRY).target(GitHub.class, "https://www.baidu.com");
		List<Map<String, String>> list = jsonObject.getListMap("OpenFeign", "feign");
		list.forEach(System.out::println);
	}

}

interface GitHub {
	// RequestLine注解声明请求方法和请求地址,可以允许有查询参数
	@RequestLine("GET /repos/{owner}/{repo}/contributors")
	List<Contributor> contributors(@Param("owner") String owner, @Param("repo") String repo);

	@RequestLine("GET /repos/{owner}/{repo}/contributors")
	List<Map<String, String>> getListMap(@Param("owner") String owner, @Param("repo") String repo);

//	@RequestLine("GET /?since={date}")
//	String list(@Param(value = "date", expander = DateToMillis.class) Date date);
}
